package com.mdz.ypxspt.Controller;


import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mdz.ypxspt.Entity.SysSpkfk;
import com.mdz.ypxspt.Entity.SysUser;
import com.mdz.ypxspt.Mapper.SysSpkfkMapper;
import com.mdz.ypxspt.Mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author 孟德志
 * @since 2019-12-15
 */
@Controller
@RequestMapping("/ypxspt/sysUser")
public class SysUserController {

    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private SysSpkfkMapper sysSpkfkMapper;

    @RequestMapping("login")
    public String login(@RequestParam(value = "loginName") String loginName, @RequestParam(value = "loginPassword") String loginPassword, @RequestParam(value = "pn", defaultValue = "1") Integer pn, @RequestParam(value = "spcmh",defaultValue = "")String spmch, ModelMap map){
        String Password= SecureUtil.md5(loginPassword);
        List<SysUser> user =sysUserMapper.selectList(new QueryWrapper<SysUser>().eq("login_name",loginName).eq("login_password",Password));
        if(user.isEmpty()){
            return "redirect:/index";
        }
        else {
            PageHelper.startPage(pn, 20);
            List<SysSpkfk> spkfkList=sysSpkfkMapper.selectList(new QueryWrapper<SysSpkfk>().like("spmch",spmch));
            PageInfo page=new PageInfo(spkfkList,5);
            map.put("pageInfo",page);
            return  "/success";
        }
    }
}

